<template>
  <div>
    <el-table :data="users" border style="width: 100%">
      <el-table-column prop="id" label="用户编号"> </el-table-column>
      <el-table-column prop="username" label="用户名"> </el-table-column>
      <el-table-column prop="rolename" label="所属角色"> </el-table-column>
      <el-table-column prop="address" label="状态">
        <template slot-scope="scoped">
          <div>
            <el-button v-if="scoped.row.status == 1" type="success"
              >启用</el-button
            >
            <el-button v-else type="info">禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scoped">
          <el-button @click="update(scoped.row.uid)" type="primary"
            >编辑</el-button
          >
          <v-del @del="del(scoped.row.uid)"></v-del>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="mangeTotal"
      :page-size="mangeSize"
      @current-change="changePage"
    >
    </el-pagination>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { userdelete } from "../../../request/api.js";
import { successAlert, warningAlert } from "../../../utils/alert.js";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      users: "user/list",
      mangeTotal: "user/total",
      mangeSize: "user/size",
    }),
  },

  methods: {
    ...mapActions({
      manageUser: "user/asyncChangeList",
      asyncMangeTotal: "user/asyncChangeTotal",
      asyncMangePage: "user/asyncChangePage",
    }),
    //删除
    del(uid) {
      userdelete({ uid: uid }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.manageUser();
          this.asyncMangeTotal();
          
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    //点击编辑
    update(uid) {
      this.$emit("update", uid);
    },
    //当前页码数
    changePage(e) {
      //当前页
      this.asyncMangePage(e);
    },
  },
  mounted() {
    //页面进来请求列表数据
    // this.manageUser();状态层请求了
    this.asyncMangeTotal()
    this.asyncMangePage(1)
  },
};
</script>

<style>
</style>